#ifndef __PTGUI_IMAGE_H__
#define __PTGUI_IMAGE_H__

#include <sys/filerw.h>
#include <gal/dc.h>

struct ptgui_image;
struct ptgui_image_engine
{
	const char				*name;
	struct pt_list_node	list;

	/* image engine function */
	pt_bool_t (*image_check)(struct pt_filerw *file);

	pt_bool_t (*image_load)(struct ptgui_image *image, struct pt_filerw *file, pt_bool_t load);
	void (*image_unload)(struct ptgui_image *image);

	void (*image_blit)(struct ptgui_image *image, struct ptgui_dc *dc, struct ptgui_rect *rect);
};

struct ptgui_image
{
	/* image metrics */
	pt_uint16_t					w;
	pt_uint16_t					h;

	/* reference count */
	pt_uint32_t					refs;

	/* image engine */
	struct ptgui_image_engine	*engine;

	/* image private data */
	void						*data;
};

/* init ptgui image system */
void ptgui_image_system_init(void);

struct ptgui_image *ptgui_image_create_from_file(const char *type, const char *filename, pt_bool_t load);
struct ptgui_image *ptgui_image_create_from_mem(const char *type, const pt_uint8_t *data, pt_size_t length,
												pt_bool_t load);
void ptgui_image_destroy(struct ptgui_image *image);

/* register an image engine */
void ptgui_image_register_engine(struct ptgui_image_engine *engine);

/* blit an image on DC */
void ptgui_image_blit(struct ptgui_image *image, struct ptgui_dc *dc, struct ptgui_rect *rect);


#endif
